﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using QzEbook.Common;
using System.Data.Common;
using System.Collections.Generic;

namespace QzEbook.AccessObject
{
    public class UserList:abstractAccess<SiteUser>
    {

        private string keyWord;

        public string KeyWord
        {
            get { return keyWord; }
            set { keyWord = value; }
        }

        public UserList()
        {
        }

        protected override SiteUser bindRow(DataRow row)
        {
            SiteUser user = new SiteUser();
            user.Uid = int.Parse(row["UID"].ToString());
            user.Name = row["UName"].ToString();
            user.LevelName = row["ULevel"].ToString();

            user.Quota = double.Parse(row["UQuota"].ToString()) / 1024;
            user.QuotaBooks = int.Parse(row["UQuotaBooks"].ToString());

            user.Gross = Math.Round(double.Parse(row["UGross"].ToString()) / 1024, 2);
            user.GrossBooks = int.Parse(row["UGrossBooks"].ToString());

            user.Sex = bool.Parse(row["USex"].ToString());
            user.From = row["UFrom"].ToString();
            user.Mail = row["UMail"].ToString();
            user.Qq = row["UQq"].ToString();
            user.Date = DateTime.Parse(row["UDate"].ToString());

            return user;
        }

        protected override DataTable selectTable()
        {
            DbCommand command = CreateCommand("SelectUserList");
            return DataAccess.ExcuteSelectCommand(command);
        }

        public List<SiteUser> SearchUser()
        {
            string sql = string.Format("SELECT * FROM Qz_User WHERE UName LIKE '%{0}%'", KeyWord);
            return bindTable(DataAccess.ExcuteSelectCommand(sql));
        }

        public DataTable UserListData()
        {
            return selectTable();
        }
    }
}